package com.cims.common.utility;


public class XMLUtils {
	public XMLUtils() {
	}

	/**
	protected static Document parseXmlFile(String xmlFilePath){
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		Document dom = null;
		
		try {
			DocumentBuilder db = dbf.newDocumentBuilder();
			dom = db.parse(xmlFilePath);
		} catch(ParserConfigurationException pce) {
			pce.printStackTrace();
		} catch(SAXException se) {
			se.printStackTrace();
		} catch(IOException ioe) {
			ioe.printStackTrace();
		}
		
		return dom;
	}

	public static void initDatabaseConnectInfor(String configFilePath) throws BoException {
		Document dom = parseXmlFile(configFilePath);
		
		if (dom == null) {
			throw new BoException("XML parser error has occurred.");
		} else {
			
			Element elDoc = dom.getDocumentElement();
			NodeList nl = elDoc.getElementsByTagName("DbConnect");
			
			if(nl != null && nl.getLength() > 0) {
				for(int i = 0 ; i < nl.getLength();i++) {
					Element el = (Element)nl.item(i);
					ApplicationConstants.DB_USER = getTextValue(el, "User");
					ApplicationConstants.DB_PASSWORD = getTextValue(el, "Pass");
					ApplicationConstants.DB_URL = getTextValue(el, "JavaConnectURL");
				}
			}
			
			try {
				new DBConnectionManager();
			} catch (Exception e) {
				e.printStackTrace();
				throw new BoException(e.getMessage());
			}
		}
	}
	
	private static String getTextValue(Element ele, String tagName) {
		String textVal = null;
		NodeList nl = ele.getElementsByTagName(tagName);
		if(nl != null && nl.getLength() > 0) {
			Element el = (Element)nl.item(0);
			textVal = el.getFirstChild().getNodeValue();
		}

		return textVal;
	}
	
	public static String getSQLFromXML(String xmlFileName, String sqlTag) throws BoException {
		Document dom = parseXmlFile(ApplicationConstants.XML_SQL_PATH + xmlFileName);
		String strSQL = "";
		
		if (dom == null) {
			throw new BoException("XML parser error has occurred.");
		} else {

			NodeList nl = dom.getElementsByTagName("System");

			if(nl != null && nl.getLength() > 0) {
				strSQL = getTextValue((Element)nl.item(0), sqlTag);
			}
		}
		
		return strSQL;
	}
	*/
}
